﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace DDDSample.Domain.Model.Locations
{
	/// <summary>
	/// A few locations for easy testing.
	/// </summary>
	public class SampleLocations
	{
		public static readonly Location HONGKONG = new Location(new UnLocode("CNHKG"), "Hongkong");
		public static readonly Location MELBOURNE = new Location(new UnLocode("AUMEL"), "Melbourne");
		public static readonly Location STOCKHOLM = new Location(new UnLocode("SESTO"), "Stockholm");
		public static readonly Location HELSINKI = new Location(new UnLocode("FIHEL"), "Helsinki");
		public static readonly Location CHICAGO = new Location(new UnLocode("USCHI"), "Chicago");
		public static readonly Location TOKYO = new Location(new UnLocode("JNTKO"), "Tokyo");
		public static readonly Location HAMBURG = new Location(new UnLocode("DEHAM"), "Hamburg");
		public static readonly Location SHANGHAI = new Location(new UnLocode("CNSHA"), "Shanghai");
		public static readonly Location ROTTERDAM = new Location(new UnLocode("NLRTM"), "Rotterdam");
		public static readonly Location GOTHENBURG = new Location(new UnLocode("SEGOT"), "Göteborg");
		public static readonly Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
		public static readonly Location NEWYORK = new Location(new UnLocode("USNYC"), "New York");

		public static readonly IDictionary<UnLocode, Location> All = new Dictionary<UnLocode, Location>();

		static SampleLocations()
		{
			foreach (FieldInfo field in typeof(SampleLocations).GetFields())
			{
				if (field.FieldType == typeof(Location))
				{
					Location location = (Location)field.GetValue(null);
					All.Add(location.UnLocode, location);
				}
			}
		}

		public static IList<Location> GetAll()
		{
			return new List<Location>(All.Values);
		}

		public static Location Lookup(UnLocode unLocode)
		{
			return All[unLocode];
		}
	}
}
